<template>
    <div class="supplyInfoMaincon">
        <div class="infolist">
          <div class="headerSelection">
            <split-vertical title="合作公司"></split-vertical>
            <v-form :formProps="searchForm" ref="form"
                    v-on:handleReset="handleReset"
                    v-on:coverFormData="coverFormData"></v-form>
          </div>
            <div class="stand">
              <div style="line-height:50px;margin-left:10px;">
                <v-button :operationBtnArray="operationBtnArray" v-on:handleSearchTopBtn="handleSearchTopBtn"></v-button>
              </div>
              <div style="margin:0 10px;">
                <v-table :tableParams="tableParams" v-on:handleOperation="handleOperation"></v-table>
              </div>
            </div>
            <div class="block">
                <el-pagination
                    @current-change="handleCurrentChange"
                    :current-page="pageIndex"
                    :page-sizes="[10]"
                    :page-size="10"
                    layout="total, sizes, prev, pager, next, jumper"
                    :total="pageCount">
                </el-pagination>
            </div>
           <!-- 弹出框组件 -->

        </div>
    </div>
</template>
<script>

import VTable from "components/common/PageTable/VTable"
import addInfo from 'components/base/SupplierInfo/AddInfo.vue'
import editInfo from 'components/base/SupplierInfo/EditInfo.vue'
import SplitVertical from "components/common/SplitVertical"
import VForm from "components/common/VForm"
import VButton from "components/common/VButton"
let changeMethods={
    '1':'直采直销',
    '2':'一件代发'
}
let companyNatureData={
  'A':'品牌方',
  'B':'供应商',
  'C':'品牌方/供应商',
  'D':'平台',
  'E':'客户'
}
export default {
    inject:['reload'],
    components:{
      addInfo,editInfo,VTable,SplitVertical,VForm,VButton
    },
    data(){
        return{
            pageCount:0,
            pageIndex:1,
            pageSize:10,
            searchForm: {
              col: 3,
              labelWidth: '100px',
              submitBtn: {
                text: '搜索'
              },
              formItemArray: [{
                label: '公司名称',
                prop: 'companyName',
                placeholder: "请输入公司名称",
                value: ''
              }, {
                label: '组织机构代码',
                prop: 'organizationCode',
                placeholder: "请输入组织机构代码",
                value: ''
              },{
                label: '状态',
                prop: 'status',
                placeholder: "请输入供应商编码",
                value: '',
                itemType: 'select',
                options: [
                  {id:1,value:0,label:"禁用"},
                  {id:2,value:1,label:"启用"}
                ],

              }]
            },
            operationBtnArray: [{
              text: '刷新',
              icon:'el-icon-refresh',
              show: true,
              type: 'primary',
              methodName: 'refresh',
            }, {
              text: '新增',
              show: true,
              icon:'el-icon-plus',
              type: 'success',
              methodName: 'add',
            }],
            tableParams:{
                dataArray:[],
                operationColumnWidth:100,
                showMultiSelection:false,
                columnArray:[
                    {label: '公司性质', prop: 'companyNature',  sortable: false,width:'130'},
                    {label: '组织机构代码', prop: 'organizationCode',sortable: false},
                    {label: '公司名称', prop: 'companyName',sortable: false},
                    {label: '公司地址', prop: 'companyAddress',sortable: false},
                    {label: '主联系人', prop: 'contactName',sortable: false,width:'120'},
                    {label: '主联系人电话', prop: 'contactMobile',sortable: false,width:'120'},
                    {label: '主联系人职位', prop: 'contactPosition',sortable: false,width:'120'}
                ],
                rowHandle:{
                    view:{
                        show:false
                    }
                }
            },
            searchCondition:{},
            id:'',
            row:{},

        }
    },
    created(){
      this.init()
    },
    methods:{
        init(){
           this.supplyList()
        },
        handleSearchTopBtn(methodName) {
          if (methodName === "refresh") {
            this.refresh();
          } else {
            this.create();
          }
        },
        handleReset(formName) {
          this.$refs.form.resetForm(formName);
        },
        coverFormData(data) {
          this.searchCondition = data;
          this.query()
        },
        handleOperation(rowIndex, row, methodName) {
              this.id=row.id;
              this.row=row;
            if(methodName == "update"){
               this.modifySupplyContent()
            }else{
              this.delSupplyContent()
            }
        },
        //初始化供应商接口
        supplyList(){
            let parmas={
              page:{
                pageIndex:this.pageIndex,
                pageSize:this.pageSize,
              }
            }
            let success=data=>{
                if(data.statusCode === '1'){
                    this.pageCount = data.body.count
                    this.tableParams.dataArray= data.body.records
                    this.tableParams.dataArray.forEach(ele=>{
                      ele.companyNature=companyNatureData[ele.companyNature]
                    })
                }else{
                    this.$message.error(data.msg)
                }
            }
            this.api.supplierList(parmas,success)
        },
        //刷新列表
        refresh(){
            this.supplyList()
        },
        //查询
        query(){
          let param = this.searchCondition;
            param["page"]={
              pageIndex : this.pageIndex,
              pageSize :this.pageSize
            }
          let success=data=>{
            if(data.statusCode === '1'){
              this.pageCount = data.body.count
              this.tableParams.dataArray= data.body.records
              this.tableParams.dataArray.forEach(ele=>{
                ele.companyNature=companyNatureData[ele.companyNature]
              })
            }else{
              this.$message.error(data.msg)
            }
          }
          this.api.supplierList(param,success)
         },
        //弹框
        create(){
          this.$router.push({
            path:'/supplier-info-add'
          })
        },
        //编辑
        modifySupplyContent(){
           this.$router.push({
             path:'supplier-info-edit',
             query:{
               id:this.id
             }
           })
        },
        //关闭弹窗
        closeDialog(){
            this.showtip=false;
            this.show=false;
        },
        delSupplyContent(){
          this.tips.ConfirmModal('确认要删除【'+this.row.companyName+'】吗？', () => {
            let param={
              id:this.id
            }
            let success=data=>{
              if(data.code=='statusCode'){
                this.$message.success("删除成功")
                this.supplyList()
              }else{
                this.$message.error(data.statusMessage)
              }
            }
            this.api.supplierDelete(param,success)
          });
        },
        //当前页
        handleCurrentChange(val) {
          this.pageIndex = val;
          this.query()
        }
    },

}
</script>
<style lang="scss" scoped>
.supplyInfoMaincon{
    width: 100%;
    height:auto;
   .infolist{
     .headerSelection{
       background:#fff;
       height:140px;
       padding: 0 10px;
       border-left: 2px solid #e8e8e8;
       border-right: 2px solid #e8e8e8;
       border-bottom: 2px solid #e8e8e8;
     }
     .stand{
       background:#fff;
     }
     .block{
       padding:10px 0;
       text-align: right;
     }
   }
}
</style>
